package Huihu.src.Homework;
import java.util.*;
/*
模拟斗地主发牌看牌
1、买牌
2、洗牌
3、发牌
4、看牌
 */
public class dome1 {
    public static void main(String[] args) {
    //买牌
        Map<Integer,String> pokers=new HashMap<>();
        List<Integer> num=new ArrayList<>();
        String [] hs={"♣","♦","♠","♥"};
        String [] zms={"3","4","5","6","7","8","9","10","J","Q","K","A","2"};
        int gs=0;
        for (String zm : zms) {
            for (String h : hs) {
                String pai=h + zm;
                pokers.put(gs,pai);
                num.add(gs);
                gs++;
            }
        }
        pokers.put(gs,"大王");
        num.add(gs++);
        pokers.put(gs,"小王");
        num.add(gs++);
        System.out.println("所有的牌："+pokers);
        System.out.println("所有的编号："+num);

        //洗牌
        Collections.shuffle(num);
        System.out.println("洗完牌后的编号："+num);

        //发牌
        List<Integer> hcy=new ArrayList<>();
        List<Integer> jjy=new ArrayList<>();
        List<Integer> sz=new ArrayList<>();
        List<Integer> dp=new ArrayList<>();
        for (int i = 0; i < num.size(); i++) {
            if (i >= num.size()-3) {
                dp.add(num.get(i));
            }
            else if (i%3==0) {
                hcy.add(num.get(i));
            }
            else if (i%3==1) {
                jjy.add(num.get(i));
            }
            else if (i%3==2) {
                sz.add(num.get(i));
            }
        }
        System.out.println("hcy:"+hcy);
        System.out.println("jjy:"+jjy);
        System.out.println("sz:"+sz);
        System.out.println("dp:"+dp);

        //看牌
        System.out.println("hcy:"+kp(hcy,pokers));
        System.out.println("jjy:"+kp(jjy,pokers));
        System.out.println("sz:"+kp(sz,pokers));
        System.out.println("dp:"+kp(dp,pokers));
    }
    public static String kp(List<Integer> list,Map<Integer,String> map) {
        Collections.sort(list);
        StringBuilder stringBuilder=new StringBuilder();
        for (Integer integer : list) {
            String sb=map.get(integer);
            stringBuilder.append(sb+" ");
        }
        String str=stringBuilder.toString();
        return  str.trim();
    }
}
